#!/usr/bin/env bash

set -eu

[ -f /sys/class/power_supply/BAT0/charge_now ] && {
    FULL_FILE=/sys/class/power_supply/BAT0/charge_full
    NOW_FILE=/sys/class/power_supply/BAT0/charge_now
}

[ -f /sys/class/power_supply/BAT0/energy_now ] && {
    FULL_FILE=/sys/class/power_supply/BAT0/energy_full
    NOW_FILE=/sys/class/power_supply/BAT0/energy_now
}

percent=$(printf "scale=2;$(cat $NOW_FILE) \
    / $(cat $FULL_FILE) \
    * 100\n" \
    | bc --mathlib)
#❚❚❚
printf "%b%% Charged\n" "$percent"
